<?php

/**
 * 
 * Enter description here ...
 * @author Ala
 *
 */
class Models_Db_Table_syntagmes extends Zend_Db_Table_Abstract
{
    /**
     * Table Name
     */
    protected $_name = 'gen_syntagmes';
    /**
     * Primary key of the table
     */
    protected $_primary = 'id_syn';
    /**
     * Verify if aleady exists
     *
     * @param array $data
     *
     * @return integer
     */
    public function exist ($data)
    {
        $select = $this->select()->from($this->_name, $this->_primary);
        foreach ($data as $k => $v) {
            $select->where($k . ' = ?', $v);
        }
        $rows = $this->fetchAll($select);
        if ($rows->count() > 0)
            $id = $rows[0]->$this->_primary;
        else
            $id = false;
        return $id;
    }
    /**
     * ADD
     *
     * @param array $data
     * @param boolean $existe
     * 
     * @return integer
     */
    public function add ($data, $exist = false)
    {
        $id = false;
        if ($exist)
            $id = $this->existe($data);
        if (! $id) {
            $id = $this->insert($data);
        }
        return $id;
    }
    /**
     * removing a col. from the DB
     * @param int:$id
     */
    public function remove ($id)
    {
        $this->delete($this->_name . "." . $this->_primary . "=" . $id);
    }
    /**
     * Updating a DB
     * @param int:$id
     * @param array:$data
     */
    public function edit ($id, $data)
    {
        $this->update($data, $this->_name . "." . $this->_primary . "=" . $id);
    }
    /**
     * selecting from a DB
     * 
     */
    public function getAll ()
    {
        $query = $this->select()->from($this->_name);
        return $this->fetchAll($query)->toArray();
    }
    /**
     * 
     * @see Zend_Db_Table_Abstract::find()
     */
    public function find ()
    {
        return null;
    }
    /**
     * 
     * @param int:$id
     */
    public function findById ($id)
    {
        $query = $this->select()->from($this->_name)->where( $this->_name . "." . $this->_primary . "= ? ", $id );
        return $this->fetchRow($query)->toArray();
    }
}
?>